package com.oom;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 运行时常量池导致的内存溢出异常
 * VM args:
 *     JDK1.7: -XX:PermSize=10M -XX:MaxPermSize=10M
 *     JDK1.8: -XX:MaxMetaspaceSize=128m
 * @author: yuchi_huang (yuchi_huang@sui.com)
 * @date: 18/3/15
 * @modified By:
 */
public class RuntimeConstantPoolOOM {

    public static void main(String[] args) {
        //使用list持有string常量池引用避免Full GC回收常量池行为, 回收常量池?
        List<String> list = new ArrayList<>();
        int i = 0;
        while(true){
            list.add(String.valueOf(i++).intern());
        }

    }

}
